<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>系统设置</title>
{{>/WEB-INF/pages/common/meta_base.part.html}}
{{>/WEB-INF/pages/common/refs_base.part.html}}
{{>/WEB-INF/pages/common/refs_modal.part.html}}
</head>
<body>
	<!-- <div class="container"> -->
	{{>/WEB-INF/pages/common/layout_header.part.html}}
	<!---内容开始---->
	<div class="container">
		<ul class="breadcrumb">
		  <li><a href="{{ctx}}">首页</a></li>
		  <li class="active">系统设置</li>
		</ul>
		<hr class="hr1" />
		<div class="hr-10"></div>
		<div class="hr-10"></div>
		<div class="hr-10"></div>
		<div class="container nr_bgc">
			<div class="bg-ga container">
				<!-- 左边导航栏 -->
				<div class="col-sm-2 left_tab">
					<ul style="margin: 0">
						<li class="leff_tab_choose">系统设置</li>
						<li id="menu-choose1"><a style="color:black;" href="{{ctx}}/mam/setting/index/1">应用类别</a></li>
						<li id="menu-choose2"><a style="color:black;" href="{{ctx}}/mam/setting/index/2">模块类别</a></li>
						<!--  
						<li id="menu-choose3"><a href="{{ctx}}/mam/setting/index/3">用户类别</a></li>
						-->
						<li id="menu-choose3"><a style="color:black;" href="{{ctx}}/system/authSetting/view">扩展认证</a></li>
						<li id="menu-choose4"><a style="color:black;" href="{{ctx}}/system/registerAudit/list">注册审核</a></li>
					</ul>

				</div>

				<!-- 右边的表格 -->
				<div class=" pull-left col-sm-10 right_tab">
					<div class="bg_green2-w">
						<div class="intro" id="introDiv"></div>
					</div>
					<div class="hr-10"></div>

					<p class="mar-st-l10">
						<button type="button" class="btn tls btn-primary btn-small"
							data-toggle="modal" href="#" onclick="enterAdd()">新增</button>
						<button type="button" class="btn tls btn-common btn-small"
							value="删除" onclick="del()">删除</button>
					</p>
					<div class="hr-10"></div>
					<div class="mar-st-lr10">
						<table id="userList" border="0" cellpadding="0" cellspacing="0"
							class="table table-bordered table-center">
							<thead>
								<tr class="title title10"
									style="background-color: rgb(248, 248, 248);">
									<th class="bd_txt2 bd_le" width="3%">
										<input id="selectAllCheckbox" class="choice-w" type="checkbox" onchange="selectAll('selectAllCheckbox','listBody')" />
									</th>
									<th class="bd_txt2 bd_le">名称</th>
									<th class="bd_txt2 bd_le">创建时间</th>
									<th class="bd_txt2 bd_le">修改时间</th>
									<th class="bd_txt2 bd_le">操作</th>
								</tr>
							</thead>
							<tbody id="listBody">
								{{#list}}
								<tr style="background-color: rgb(255, 255, 255);">
									<td class="bd_txt3"><input class="choice-w"
										type="checkbox" name="cb" id="{{id}}" value="{{id}}" /></td>
									<td class="bd_txt3">{{name}}</td>
									<td class="bd_txt3"><script type="text/javascript">
										document.write($.format.date(
												"{{create_time}}",
												"yyyy-MM-dd HH:mm"))
									</script></td>
									<td class="bd_txt3"><script type="text/javascript">
										document.write($.format.date(
												"{{modified_time}}",
												"yyyy-MM-dd HH:mm"))
									</script></td>

									<td class="bd_txt3">
										<button type="button" class="btn tls btn-common btn-small"
											onclick="enterEdit('{{id}}')">编辑</button>
									</td>
								</tr>
								{{/list}}
							</tbody>
						</table>
						{{#page}} {{>/WEB-INF/pages/common/pagination.part.html}}
						{{/page}}
					</div>


				</div>
			</div>
		</div>
		{{>/WEB-INF/pages/common/layout_footer.part.html}}
	</div>
</body>
</html>

<script type="text/javascript">
	var type = "{{type}}";
	$(function() {
		$('#menu-choose' + type).attr("class", "menu-choose");
		var textValue = $('.menu-choose a' ).text();
		$('#introDiv').text(textValue);
	});

	function enterAdd() {
		var loadurl = '{{ctx}}/mam/setting/enterAdd/' + type;
		$.get(loadurl, function(data) {
			bootbox.dialog({
				message : data,
				title : "",
				buttons : {
					danger : {
						label : "关闭",
						className : "btn btn-common btn-small tls"
					},

					success : {
						label : "保存",
						className : "btn btn-primary btn-small tls",
						callback : function() {
							submitForm();
							return false;
						}
					}
				}
			});
		});
	}

	function enterEdit(id) {
		var loadurl = '{{ctx}}/mam/setting/enterUpdate/' + id;
		$.get(loadurl, function(data) {
			bootbox.dialog({
				message : data,
				title : "",
				buttons : {
					danger : {
						label : "关闭",
						className : "btn btn-common btn-small tls"
					},
					success : {
						label : "保存",
						className : "btn btn-primary btn-small tls",
						callback : function() {
							submitForm();
							return false;
						}
					}
				}
			});
		});
	}

	/* 获取多选框项id */
	function getIds() {
		var checkIdentifys = [];
		$("#listBody input[type='checkbox']").each(function(index) {
			if ($(this).is(':checked')) {
				var id = $(this).val();
				checkIdentifys.push(id);
			}
		});
		return checkIdentifys;
	}

	function selectAll(id,parent){
		var selectAllCheckbox = $("#"+id);
		var checkList = $("#"+parent+" input[type='checkbox']");
		if(selectAllCheckbox.is(':checked')){
			checkList.each(function(index) {
				this.checked = true;
			});
		}else{
			checkList.each(function(index) {
				this.checked = false;
			});
		}
	}
	
	function del() {
		var checkIdentifys = getIds();
		if (checkIdentifys == 0) {
			bootbox.alert("请选择删除项");
			return;
		}
		var data = [ {
			name : 'ids',
			value : checkIdentifys
		}, {
			name : 'type',
			value : type
		} ];
		
		
		bootbox.confirm("确定要删除吗?", function(result) {
			if (result) {
				$.ajax({
					async : true,
					type : "POST",
					url : "{{ctx}}/mam/setting/delete",
					data : data,
					dataType : 'json',
					success : function(data, textStatus) {
						if(data.result == "success"){
							bootbox.alert("删除成功！", function() {
								$("body input[type='checkbox']").attr("checked",false);
								window.location.reload();
							});
						}else{
							if(data.type == "1"){
								bootbox.alert("应用类别中含有应用，无法进行删除！");
							}else if(data.type == "2"){
								bootbox.alert("模块类别中含有模块，无法进行删除！");
							}
						}
						
					},
					error : function(data, status, e) {
						alert(e);
					}
				});
			}
		});
		
	}
</script>
